package com.ruoyi.webs.utils.listener;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;


public class RequestListener
        implements ServletRequestListener {
    public void requestDestroyed(ServletRequestEvent sre) {
        ServletContext servletContext = sre.getServletContext();
        HttpServletRequest servletRequest = (HttpServletRequest) sre.getServletRequest();
        String requestURI = servletRequest.getRequestURI();

        Object attribute = servletContext.getAttribute("loginTimes");
        Object attribute2 = servletContext.getAttribute("requestTimes");
        if (attribute == null) {
            servletContext.setAttribute("loginTimes", Integer.valueOf(0));
        }
        if (attribute2 == null) {
            servletContext.setAttribute("requestTimes", Integer.valueOf(0));
        }
        int loginTimes = ((Integer) servletContext.getAttribute("loginTimes")).intValue();
        int requestTimes = ((Integer) servletContext.getAttribute("requestTimes")).intValue();

        if (StringUtils.equals("/hlhzxh/a", requestURI)) {
            if (loginTimes == 0) {
                servletContext.setAttribute("loginTimes", Integer.valueOf(1));
            } else {
                servletContext.setAttribute("loginTimes", Integer.valueOf(loginTimes + 1));
            }

        } else if (requestTimes == 0) {
            servletContext.setAttribute("requestTimes", Integer.valueOf(1));
        } else {
            servletContext.setAttribute("requestTimes", Integer.valueOf(requestTimes + 1));
        }


        int newloginTimes = ((Integer) servletContext.getAttribute("loginTimes")).intValue();
        int newrequestTimes = ((Integer) servletContext.getAttribute("requestTimes")).intValue();
    }

    public void requestInitialized(ServletRequestEvent sre) {
    }
}